package com.tanhua.manager.controller;

import com.tanhua.manager.service.AnalysisByDayService;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/dashboard")
public class DashboardController {

    @Autowired
    private AnalysisByDayService analysisByDayService;

    @GetMapping(value = "/summary", name = "概要统计信息")
    public ResponseEntity querySummary() {
        return analysisByDayService.querySummary(DateTime.now().toString("yyyy-MM-dd"));
    }

    /**
     * 后台管理系统折线图
     *
     * @param sd  开始时间
     * @param ed  结束时间
     * @param type  101 新增 102 活跃用户 103 次日留存率
     * @return object[] thisYear 本年 --> string title 日期, integer amount 数量
     *         object[] lastYear 去年 --> string title 日期, integer amount 数量
     */
    @GetMapping(value = "/users", name = "新增、活跃用户、次日留存率")
    public ResponseEntity queryUsers(Long sd, Long ed, Integer type) {
        return analysisByDayService.queryUsers(sd, ed, type);
    }
}
